package com.ocm.tourism.core.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Version;

import org.springframework.security.core.GrantedAuthority;

@SuppressWarnings("serial")
@Entity
public class SecurityRole implements GrantedAuthority{

   @Enumerated(EnumType.STRING)
   private RoleType roleType;

   @ManyToOne
   private Participant participant;

   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_SECURITYROLE")
   @TableGenerator(name = "GEN_SECURITYROLE", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "SECURITYROLE")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public RoleType getRoleType() {
      return roleType;
   }

   public void setRoleType(RoleType roleType) {
      this.roleType = roleType;
   }

   public Participant getParticipant() {
      return participant;
   }

   public void setParticipant(Participant participant) {
      this.participant = participant;
   }

   @Override
   public String getAuthority() {
      return roleType.name();
   }

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }
}
